package com.ruoyi.web.controller.inventory;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.InvInventoryTransferDetail;
import com.ruoyi.system.service.IInvInventoryTransferDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.util.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存调拨详情Controller
 *
 * @author ruoyi
 * @date 2023-07-18
 */
@RestController
@RequestMapping("/transfer/inventoryTransferDetail")
@Api(tags = "库存调拨详情管理")
public class InvInventoryTransferDetailController extends BaseController {

    @Autowired
    private IInvInventoryTransferDetailService invInventoryTransferDetailService;

    /**
     * 查询库存调拨详情列表
     */
    @GetMapping("/list")
    @ApiOperation("查询库存调拨详情列表")
    public TableDataInfo list(InvInventoryTransferDetail invInventoryTransferDetail) {
        startPage();
        QueryWrapper<InvInventoryTransferDetail> queryWrapper = new QueryWrapper<>(invInventoryTransferDetail);
        List<InvInventoryTransferDetail> list = invInventoryTransferDetailService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 获取库存调拨详情详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取库存调拨详情详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(invInventoryTransferDetailService.getById(id));
    }

    /**
     * 新增库存调拨详情
     */
    @PostMapping
    @ApiOperation("新增库存调拨详情")
    public AjaxResult add(@RequestBody InvInventoryTransferDetail invInventoryTransferDetail) {
        return toAjax(invInventoryTransferDetailService.save(invInventoryTransferDetail));
    }

    /**
     * 修改库存调拨详情
     */
    @PutMapping
    @ApiOperation("修改库存调拨详情")
    public AjaxResult edit(@RequestBody InvInventoryTransferDetail invInventoryTransferDetail) {
        return toAjax(invInventoryTransferDetailService.updateById(invInventoryTransferDetail));
    }

    /**
     * 删除库存调拨详情
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("删除库存调拨详情")
    public BaseResponse<Boolean> remove(@PathVariable Long[] ids) {
        return BaseResponse.success(invInventoryTransferDetailService.removeByIds(java.util.Arrays.asList(ids)));
    }

    /**
     * 导出库存调拨详情列表
     */
    @PostMapping("/export")
    @ApiOperation("导出库存调拨详情列表")
    public void export(HttpServletResponse response, InvInventoryTransferDetail invInventoryTransferDetail) {
        QueryWrapper<InvInventoryTransferDetail> queryWrapper = new QueryWrapper<>(invInventoryTransferDetail);
        List<InvInventoryTransferDetail> list = invInventoryTransferDetailService.list(queryWrapper);
        ExcelUtil<InvInventoryTransferDetail> util = new ExcelUtil<>(InvInventoryTransferDetail.class);
        util.exportExcel(response, list, "库存调拨详情数据");
    }
}
